package moyangjia.retailers.uims.api;

import moyangjia.retailers.common.domain.R;
import moyangjia.retailers.storage.common.domain.R;
import moyangjia.retailers.storage.sys.domain.SysDict;
import moyangjia.retailers.storage.sys.service.IDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description:
 * @author: honglei
 * @time: 2021/3/15 0015 14:10
 */
@RestController
@RequestMapping("/api/uims/dict/")
public class DictController {
    @Autowired
    IDictService dictService;


    @PostMapping("add")
    public R addDict(SysDict sysDict) {
        return R.ok(dictService.save(sysDict));
    }

    @PostMapping("remove/{id}")
    public R remove(@PathVariable(value = "id") String id) {
        return R.ok(dictService.removeById(id));
    }

    @PostMapping("removeList")
    public R removeList(List<String> ids) {
        return R.ok(dictService.removeByIds(ids));
    }
    @PostMapping("update")
    public R update(SysDict  sysDict) {
        if (null==sysDict||null==sysDict.getId()){
            return R.error(40001,"id不存在");
        }
        return R.ok(dictService.updateById(sysDict));
    }


    @GetMapping("get/{id}")
    public R getDict(@PathVariable(value = "id") String id) {
        SysDict sysDict=dictService.getById(id);
        if (sysDict==null){
            return R.error(40001,"id不存在");
        }
        return R.ok(sysDict);
    }

    @GetMapping("getDictList")
    public R getDictList(SysDict sysDict) {
        return R.ok(dictService.getDictList(sysDict));
    }



}
